home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / kbd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  3.6 KB  |  173 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: kbd.c,v 1.1 89/03/17 08:21:15 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/kbd.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/kbd.c,v $$Revision: 1.1 $";
  12.  
  13. #include <stdio.h>
  14. #include <sys/signal.h>
  15. #include "bitmap.h"
  16. #include "defs.h"
  17. #ifdef sun
  18. #include <sys/time.h> 
  19. #ifdef KBD
  20. # include <sys/types.h>
  21. # include <sundev/kbio.h>
  22. # include <sys/ioctl.h>
  23. #endif KBD
  24. #endif
  25.  
  26. static int    bell_fd;
  27.  
  28. /* initialize bell, for Suns */
  29. int
  30. initbell()
  31.    {
  32. #ifdef BELL
  33.    int i;
  34.    if ( !debug  &&  (i=open("/dev/bell",1))>=0 )
  35.       bell_fd = i;
  36.    else
  37.       bell_fd = -1;
  38. #endif
  39.    }
  40.  
  41.  
  42.  
  43. static int ring = 0;
  44.  
  45. /* turn on the bell */
  46.  
  47. void
  48. bell_on()
  49.    {
  50. #ifdef BELL
  51.    int    bell_off();
  52.  
  53.    if( bell_fd >= 0 ) {
  54.       if (ring==0)
  55.          write( bell_fd, "\002", 1 );
  56.       signal( SIGALRM, bell_off );
  57.       set_timer(15);        /* set alarm for 100'th seconds */
  58.       ring++;
  59.       return;
  60.       }
  61. #endif
  62. /*    We are looking for some way to make a noise when ever possible.
  63.       This line breaks when the console is redirected to an mgr window and
  64.       mgr's stderr (fd 2) is the console.
  65.  
  66.    write( 2, "\007", 1 );
  67. */
  68.    }
  69.  
  70. #ifdef BELL
  71. /* turn off the bell */
  72.  
  73. int
  74. bell_off(n)
  75. int n;            /* signal #, ignored */
  76.    {
  77.    write(bell_fd,"\003",1);    /* turns the bell off */
  78.    set_timer(0);        /* insure timer is off */
  79.    ring = 0;
  80.    }
  81.  
  82.  
  83. /* reset the keyboard */
  84.  
  85. int
  86. kbd_reset()
  87.    {
  88.    if( bell_fd >= 0 )
  89.       write(bell_fd,"\001",1);    /* this resets the kbd and turns bell off */
  90.    set_timer(0);        /* insure timer is off */
  91.    ring = 0;
  92.    }
  93.  
  94.  
  95. int
  96. set_timer(time)
  97. int time;        /* time in 100'th of seconds */
  98.    {
  99.    struct    itimerval new,old;
  100.  
  101.    new.it_interval.tv_sec = 0L;
  102.    new.it_interval.tv_usec = 0L;
  103.    new.it_value.tv_sec = time/100;
  104.    new.it_value.tv_usec = (time%100) * 10000;
  105.  
  106.    setitimer(ITIMER_REAL,&new,&old);
  107.    }
  108.  
  109. #else
  110. int
  111. kbd_reset() {}
  112. #endif
  113.  
  114. static int kbd_fd = -1;
  115.  
  116. /* initialize the keyboard, especially when it is a separate device */
  117.  
  118. initkbd()
  119. {
  120. #ifdef KBD
  121.    int fd;
  122.  
  123.    if ((fd = set_kbd(1)) > 0) {
  124.     kbd_fd = 0; 
  125.        close(kbd_fd);
  126.     dup(fd);
  127.     close(fd);
  128.     }
  129.    else if( fd == 0 )
  130.     return;
  131.    else  {
  132.     if( debug )
  133.        fprintf(stderr,"Can't find keyboard, using stdin\n");
  134.     kbd_fd = -1;
  135.     }
  136. #endif
  137. }
  138.  
  139. /* set/reset direct mode
  140.    When setting direct mode, returns file descriptor of keyboard */
  141.  
  142. int
  143. set_kbd(how)
  144. int how;            /* 1=direct, 0=no direct */
  145.    {
  146.    int one = 1;
  147.    int zero = 0;
  148.    int cons;
  149.  
  150. #ifdef KBD
  151. #ifndef  KBD_CMD_RESET
  152. #define  KBD_CMD_RESET    0x01    /* Should be in a header file, but .. */
  153. #endif
  154.    if (how == 0) {        /* make sure kbd is released */
  155.       if (kbd_fd == -1)
  156.      return(-1);
  157.       ioctl(kbd_fd, KIOCSDIRECT, &zero);    /* turn off direct mode */
  158.       ioctl(kbd_fd, KIOCCMD, KBD_CMD_RESET);    /* reset the keyboard */
  159.       close(kbd_fd);                /* close the keyboard */
  160.       cons = open("/dev/console", 0);    /* put console messages back */
  161.       ioctl(cons, TIOCCONS, &one);
  162.       close(cons);
  163.       return(0);
  164.       }
  165.    else {        /* open the kbd for input */
  166.       kbd_fd = open("/dev/kbd", 0);
  167.       ioctl(kbd_fd, KIOCSDIRECT, &one);        /* turn on direct mode */
  168.       ioctl(kbd_fd, KIOCCMD, KBD_CMD_RESET);    /* reset the keyboard */
  169.       }
  170. #endif
  171.    return(kbd_fd);
  172.    }
  173.